package cn.datax.service.system.service.impl;

import cn.datax.common.base.BaseServiceImpl;
import cn.datax.common.exception.DataException;
import cn.datax.service.system.api.dto.DeptDto;
import cn.datax.service.system.api.dto.NoticeDto;
import cn.datax.service.system.api.entity.DeptEntity;
import cn.datax.service.system.api.entity.DeptRelationEntity;
import cn.datax.service.system.api.entity.NoticeEntity;
import cn.datax.service.system.dao.DeptDao;
import cn.datax.service.system.dao.DeptRelationDao;
import cn.datax.service.system.dao.NoticeDao;
import cn.datax.service.system.mapstruct.DeptMapper;
import cn.datax.service.system.mapstruct.NoticeMapper;
import cn.datax.service.system.service.DeptService;
import cn.datax.service.system.service.NoticeService;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jimmy
 * @since 2022-07-30
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class NoticeServiceImpl extends BaseServiceImpl<NoticeDao, NoticeEntity> implements NoticeService {

    @Autowired
    private NoticeDao noticeDao;

    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public NoticeEntity saveNotice(NoticeDto noticeDto) {
        NoticeEntity notice = noticeMapper.toEntity(noticeDto);
        noticeDao.insert(notice);
        return notice;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public NoticeEntity updateNotice(NoticeDto noticeDto) {
        NoticeEntity notice = noticeMapper.toEntity(noticeDto);
        noticeDao.updateById(notice);
        return notice;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteNoticeById(String id) {
        noticeDao.deleteById(id);
    }
}
